<?php
namespace app\Admin\controller;
use app\admin\controller\Base;
use think\Db;
use think\Session;
use app\Admin\model\Cate as CateModel;
class Cate extends Base
{
    public function lst()
    {
        $list=CateModel::paginate(3);
        $this->assign('list', $list);
        return $this->fetch();
    }
	 public function add()
    {
    	if(request()->isPost()){



    		$data=[
    			'catename'=>input('catename'),
    			
    		];

                $validate = \think\Loader::validate('Cate');
                if(!$validate->scene('add')->check($data)){
                    $this->error($validate->getError());
                    die;
                }
                
    		if(Db::name('Cate')->insert($data)){
    			return $this->success("添加导航成功","lst");
    		}else{
    			return $this->error("添加导航失败！！！");
    		}
    		return;
    	}
        return $this->fetch();
    }


    public function edit(){
         $id=input('id');
        $Cates=db('Cate')->find($id);
        
        if(request()->isPost()){
            $data=[
            'id'=>input('id'),
            'catename'=>input('catename'),
            ];

           
            $validate = \think\Loader::validate('Cate');
                if(!$validate->scene('edit')->check($data)){
                    $this->error($validate->getError());
                    die;
                        }

             
            if(db('Cate')->update($data)){
                $this->success('修改成功','lst');
            }else{
                $this->error('修改失败');
            }
            return;
        }
       $this->assign('Cates',$Cates);
        return $this->fetch();
    }

    public function del(){
        $id=input('id');
        if($id!=1){
            if(db('Cate')->delete(input('id'))){
                $this->success('删除导航成功！','lst');
            }else{
                $this->error('删除导航失败！');
            }
        }else{
            $this->error('主要东西不能删除！！！');
        }
    }







}

?>